import { resolve } from 'path'
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import vue from '@vitejs/plugin-vue'
import { log } from 'console'

export default defineConfig({
	main: {
		plugins: [externalizeDepsPlugin()]
	},
	preload: {
		plugins: [externalizeDepsPlugin()]
	},
	renderer: {
		base: './',
		plugins: [vue()],
		resolve: {
			alias: {
				// '@': '/src' // 简单的配置可能无法正常工作，因为需要确保路径是相对于项目根目录的  
				// 更好的配置是使用 path 模块来确保路径正确  
				'@': resolve(__dirname, 'src/renderer/src'), // 注意：需要导入 path 模块  
			},
		},
		server: {
			host: '127.0.0.1',
			port: 7001,
			proxy: {
				'/api': {
					target: 'http://localhost:8081',
					ws: true,
					changeOrigin: true,
					rewrite: (path) => path.replace(/^\/api/, '')
				},
				'/filePath': {
					target: 'http://localhost:10001',
					changeOrigin: true,
					rewrite: (path) => {
						const prefix = '/download?fileName=';
						const fileName = decodeURIComponent(path.replace(/^\/filePath/,''));
						const encode = encodeURIComponent(fileName);
						return prefix + encode;
					}
				},
			}
		}
	},
})
